package zx.x.modules.yshapp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import zx.x.common.utils.PageUtils;
import zx.x.common.utils.R;
import zx.x.modules.app.dao.UserDao;
import zx.x.modules.app.entity.UserEntity;
import zx.x.modules.yshapp.dto.PointVo;
import zx.x.modules.yshapp.entity.PointEntity;
import zx.x.modules.yshapp.service.PointService;

import java.util.List;
import java.util.Map;


/**
 *签到积分日历
 */
@RestController
@RequestMapping("yshapp/point")
public class PointAppController {
    @Autowired
    private PointService pointService;
    @Autowired
    private UserDao userDao;

    /**
     * 签到积分日历
     */
    @RequestMapping("/monthlyPoint")
    public R monthlyPoint(@RequestParam Map<String, Object> params){
        List<PointEntity> pointList = pointService.getMonthlyPoint(params);
        return R.ok().put("pointList", pointList);
    }

    /**
     * 积分签到
     */
    @RequestMapping("/signIn")
    public R signIn(Integer userId){
        int point = pointService.signIn(userId);
        if(point == 0){
            return R.error("今日已签到");
        }
        return R.ok().put("point", point);
    }

    /**
     * 获取用户可用总积分
     * @param userId
     * @return
     */
    @RequestMapping("/getPoint")
    public R getPoint(Integer userId){
        UserEntity user = userDao.selectById(userId );
        return R.ok().put("point", user.getPoint());

    }
    /*
    * 已签到日数(包括总积分)
     */
    @RequestMapping("/getPointInfo")
    public R getPointInfo(Integer userId){
       int signIndays = pointService.signIndays(userId);
        UserEntity user = userDao.selectById(userId );
        PointVo pointVo = new PointVo();
        pointVo.setSignIndays(signIndays);
        pointVo.setTotalPoint(user.getPoint());
        return R.ok().put("pointVo", pointVo);
    }

    @RequestMapping("/signInPointList")
    public R signInPointList(@RequestParam Map<String, Object> params){
        PageUtils page = pointService.queryPage(params);

        return R.ok().put("page", page);
    }





}
